<template>
	<view class="content" >
		<!-- <view class="cate">
			<view class="zs"  :class="[selected==2?'ac':'']" @tap="menu(2)">随机区 <text class="bottom-line"></text> </view>
			<view class="zs" :class="[selected==1?'ac':'']" @tap="menu(1)">擂台区 <text class="bottom-line"></text></view>
			<view class="zs" :class="[selected==3?'ac':'']" @tap="menu(3)">抽赏区 <text class="bottom-line"></text></view>
			<view class="zs" :class="[selected==4?'ac':'']" @tap="menu(4)">积分区 <text class="bottom-line"></text></view>
		</view> -->
		<view
			:style="'padding:'+(banner.style && banner.style.margin)+'rpx; margin-top:' + (banner.style && banner.style.margin_top) + 'rpx;'"
			v-cloak>
			<view class="swiper-wrap" :style="{height:banner.style.height + 'rpx'}">
				<swiper autoplay @change="change">
					<swiper-item v-for="(item, index) in banner.list" :key="index">
						<image mode="aspectFill" :src="item.image + '?x-oss-process=image/resize,w_1200'"
							:style="{'border-radius':banner.style.radius + 'rpx'}" class="slide-image" :data-item="item"
							@tap="handleClick" />
					</swiper-item>
				</swiper>
				<view class="dots">
					<view class="dot-item" :class="{active:current==index}" v-for="(item,index) in banner.list"
						:key="index">
					</view>
				</view>
			</view>
		</view>
		<view class="cate">
			<image class="img-bg" src="../../static/new/cate_bg.png" mode=""></image>
			<div class="cate-box">
				<view class="zs" :class="[selected==2?'ac':'']" @tap="menu(2)">
					<image class="cate-icon" src="../../static/new/sjq.png" mode=""></image>
					<text>随机区</text>
					<text class="bottom-line"></text>
				</view>
				<view class="zs" :class="[selected==1?'ac':'']" @tap="menu(1)">
					<image class="cate-icon" src="../../static/new/ltq.png" mode=""></image>
					<text>擂台区</text>
					<!-- <text class="bottom-line"></text> -->
				</view>
				<view class="zs" :class="[selected==3?'ac':'']" @tap="menu(3)">
					<!-- <text class="bottom-line"></text> -->
					<image class="cate-icon" src="../../static/new/cjq.png" mode=""></image>
					<text>抽赏区</text>
				</view>
				<view class="zs" :class="[selected==4?'ac':'']" @tap="menu(4)">
					<image class="cate-icon" src="../../static/new/jfq.png" mode=""></image>
					<text>积分区</text>
					<!-- <text class="bottom-line"></text> -->
				</view>
			</div>
			<!---->
		</view>
		<view class="goods" v-if="!kong">
			<view class="item" v-for="item in listInfo" @tap="info(item)">
				<view class="item-box">
					<image class="face" :src="item.thumb" mode="widthFix"></image>
					<view class="title">
						{{item.title_app?item.title_app:item.title}}
					</view>
					<!-- <view class="tips">
						现货&预售 12:00刷新
					</view> -->
					<view class="prize" v-if="item.money_price > 0">
						<view class="left">
							<span style="font-size: 20rpx;color: #FF0000;">￥</span>
							<span style="font-size: 24rpx;font-weight: bold;color: #FF0000;">{{formatPrice(item.money_price)}}</span>
							<span style="font-size: 22rpx;color: #B1A396;">/张</span>
						</view>
						<view class="right">
							<span v-if="item.play_type ==5 || item.play_type ==4">1/{{item.now_id}}箱</span>
							<span v-else>{{item.rand}}/{{item.cnt}}箱</span>
						</view>
					</view>
					<view class="prize" v-else>
						<view class="left">
							<span style="font-size: 20rpx;transform: scale(0.5);margin-left: 10rpx;">积分</span>
							<span style="font-size: 24rpx;font-weight: bold;color: #FF0000;">{{item.score_price}}</span>
							<span style="font-size: 22rpx;color: #B1A396;">/张</span>
						</view>
						<view class="right">
							<span v-if="item.play_type ==5 || item.play_type ==4">1/{{item.now_id}}箱</span>
							<span v-else>{{item.rand}}/{{item.cnt}}箱</span>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="kong" v-else>
			<view>暂无活动</view>
			<image src="../../static/activity/qin.png" mode="widthFix"></image>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				zsac: 'ac',
				sqac: '',
				listInfo: '',
				stock_no: 1,
				kong: true,
				playType: '/leitais_group?play_type=3',
				infoType: 'leiTai',
				scrollTop: 0,
				refreshCounter1: 0,
				getNextPageCounter: 0,
				selected: 2,
				banner: [],
				current: 0
			}
		},

		onLoad() {
			console.log(1234)
			this.$http('/setting/base').then(res => {
				console.log(res)
				// console.log(res.data.setting.shop_home.modules.filter((e)=>e.type=="swiper"))
				res.data.setting.shop_home.modules.forEach(item => {
					if (item.type == 'swiper') {
						this.banner = item
					}
				})

			}).catch((err)=>{
				console.log(err)
			})

			this.getData()
		},

		// onPullDownRefresh() {
		// 	this.$showPullRefresh().then(res => {
		// 		this.refreshCounter1++
		// 	})
		// },

		// onReachBottom() {
		// 	this.getNextPageCounter++
		// 	// console.log('reach bottom')
		// },
		// onPageScroll(e) {
		// 	this.scrollTop = e.scrollTop
		// },


		methods: {
			randomNumber(num) {
				console.log(12345);
				return Math.floor(Math.random() * num + 1);
			},
			change(e) {
				this.current = e.detail.current
			},
			handleClick(e) {
				let item = e.currentTarget.dataset.item
				let link = item.link || {}
				this.toLink(link)
			},
			GetRequest(url) {
				//获取url中"?"符后的字串  
				var theRequest = new Object();
				if (url.indexOf("?") != -1) {
					url = "?" + url.split("?")[1]; //模拟获取参数后面的
					var str = url.substr(1);
					let strs = str.split("&");
					for (var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);

					}
				}
				return theRequest;
			},
			menu(e) {
				this.selected = e
				if (e == 1) {
					this.playType = '/leitais_group';
					this.infoType = 'leiTai';
				} else if (e == 2) {
					this.playType = '/leitais_group?play_type=3';
					this.infoType = 'leiTai';
				} else if (e == 3) {
					this.playType = '/choushangs_group?play_type=1';
					this.infoType = 'chouShang';
				} else {
					this.playType = '/choushangs_group?play_type=2';
					this.infoType = 'chouShang';
				}

				uni.showLoading({
					'mask': true,
					'title': '加载中...'
				})

				this.getData();
			},

			getData() {
				var url = this.playType;
				this.$http(url, 'GET', {
					stock_no: this.stock_no
				}).then(res => {
					console.log(res);
					// 2.3.27 新增替换需求
					this.listInfo = res.data;
					if (res.data.length > 0) {
						this.kong = false;
						this.listInfo.forEach(item => {
							item.rand = this.randomNumber(item.cnt);
						})
					} else {
						this.kong = true;
					}

					uni.hideLoading()
				})
			},

			check(e) {
				if (e == 1) {
					this.zsac = 'ac';
					this.sqac = '';
					this.stock_no = 1;
					this.getData()
				} else {
					this.zsac = '';
					this.sqac = 'ac';
					this.stock_no = 0;
					this.getData()
				}
			},

			info(e) {
				var url = "/packageA/pages/" + this.infoType + "/index?title=";
				uni.navigateTo({
					url: url + encodeURIComponent(e.title) + "&imgUrl=" + e.thumb
				})
			},
			formatPrice(price) {
				return (price / 100).toFixed(2)
			},
		},


	}
</script>

<style lang="scss" scoped>
	.content {
		background: #F2F3F4;
		min-height: 100vh;
		height: 100%;
		box-sizing: border-box;
		// background-color: red;
		// padding: 0 56rpx;
	}

	.swiper-wrap {
		width: 100%;
		// height: 100%;
		// position: relative;
		padding: 0 26rpx;
		box-sizing: border-box;

		swiper {
			height: 100%;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.dots {
		position: relative;
		left: 0;
		bottom: 30rpx;
		width: 100%;
		height: 8rpx;
		display: flex;
		justify-content: center;

		.dot-item {
			margin: 0 6rpx;
			width: 10rpx;
			height: 10rpx;
			border-radius: 50%;
			background-color: rgba(255, 255, 255, 0.6);
			transition: all 0.4s;


		}

		.active {
			border-radius: 6rpx;
			width: 26rpx;
			background-color: #FD9D11;
		}
	}

	.cate {
		font-size: 28rpx;
		color: #AEAEAE;
		height: 230rpx;
		width: 100%;
		position: relative;
		box-sizing: border-box;
		padding: 26rpx 26rpx 0;

		.img-bg {
			position: absolute;
			top: 0;
			left: 26rpx;
			height: 100%;
			width: calc(100vw - 52rpx);
			margin-top: 30rpx;
			z-index: 2;
		}

		.cate-box {
			display: flex;
			align-items: center;
			width: 100%;
			height: 100%;
			position: relative;
			z-index: 3;

			.zs {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				height: 100%;
				width: 25%;

				.cate-icon {
					width: 100rpx;
					height: 100rpx;
				}
			}
		}

		.ac {
			color: #262626;
		}

	}

	.goods {
		// margin-top: 24rpx;
		background-color: #fff;
		box-shadow: 0 -4rpx 10rpx -2rpx #efefef;
		position: relative;
		z-index: 999;
		border-radius: 32rpx 32rpx 0rpx 0rpx;
		overflow: hidden;
		padding: 30rpx;
		display: flex;
		flex-wrap: wrap;
	}

	.item {
		width: 50%;
		padding-right: 10rpx;
		box-sizing: border-box;
		margin-bottom: 32rpx;

		&:nth-child(2n) {
			padding-left: 10rpx;
			padding-right: 0;
			box-sizing: border-box;
		}

		.item-box {
			background-color: #F9F6F4;
			border-radius: 32rpx 32rpx;
			overflow: hidden;
		}

		.face {
			width: 100%;
			border-radius: 32rpx 32rpx 0rpx 0rpx;
		}

		.title {
			font-size: 30rpx;
			font-family: PingFang;
			font-weight: 500;
			color: #493A2C;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			margin-top: 16rpx;
			font-size: 24rpx;
			padding-left: 12rpx;
		}

		.prize {
			margin-top: 16rpx;
			display: flex;
			justify-content: space-between;
			font-size: 20rpx;
			padding: 0 20rpx 24rpx 12rpx;
			.right {
				color: #B1A396;
				font-size: 20rpx;
			}
		}


	}

	.kong {
		width: 100%;
		margin-top: 10vh;
		text-align: center;
		// background-color: red;
		color: #A6A6A6;
		font-size: 25rpx;

		image {
			width: 20%;
		}
	}
</style>